<?php
/**
 * Created by PhpStorm.
 * User: 何婷婷
 * Date: 2016/
 * 11/8
 * Time: 17:21
 */
namespace App\Core;

class Router
{
    private $con;
    private $act;
    private $routes;

    function __construct()
    {
        $this->routes = @include_once(CONFIG_PATH . '/route.php');
        $this->con = isset($_GET['con']) ? $_GET['con'] : 'user';
        $this->act = isset($_GET['act']) ? $_GET['act'] : 'show_login';
    }

    public function match()
    {
        if (key_exists($this->con, $this->routes)) {
            if (key_exists($this->act, $this->routes[$this->con])) {
                $tmp = explode('@', $this->routes[$this->con][$this->act]);
                $tmp[0] = "App\\Controller\\" . $tmp[0];
                return $tmp;
            }
        }
        exit("action isn't exist.");
    }

    public function printRouteList()
    {
        var_dump($this->routes);
    }

}